package v1

import (
	bll "aggregation/bll/dashboard"
	model "aggregation/model/dashboard"
	"auth/utils"
	"github.com/gin-gonic/gin"
	"strings"
)

type app struct {
}

var App = &app{}

func (a *app) Init(r *gin.RouterGroup) {
	router := r.Group("/dashboard/user") //, middleware.Auth())
	{
		router.GET("/board", a.userBoard)
		router.GET("/wave", a.userWave)
		router.GET("/complain/board", a.complainBoard)
		router.GET("/complain/wave", a.complainWave)
		router.GET("/active/board", a.activeUserBoard)
		router.GET("/active/wave", a.activeUserWave)
		router.GET("/summary", a.userSummary)
	}
}

func (a *app) userBoard(ctx *gin.Context) {
	var (
		board model.UserBoardResponse
		err   error
	)
	if board, err = bll.User.AppUserBoard(ctx.Request.Context()); err != nil {
		ctx.Error(err)
		return
	}
	utils.ResponseOK(ctx, board)
}

func (a *app) userWave(ctx *gin.Context) {
	var (
		period string
		wave   model.UserWaveResponse
		err    error
	)
	period = strings.TrimSpace(strings.ToLower(ctx.DefaultQuery("period", "day")))
	if wave, err = bll.User.AppUserWave(ctx.Request.Context(), model.PERIOD(period)); err != nil {
		ctx.Error(err)
		return
	}
	utils.ResponseOK(ctx, wave)
}

func (a *app) complainBoard(ctx *gin.Context) {
	var (
		board model.UserComplaintBoardResponse
		err   error
	)
	if board, err = bll.User.ComplainBoard(ctx.Request.Context()); err != nil {
		ctx.Error(err)
		return
	}
	utils.ResponseOK(ctx, board)
}
func (a *app) complainWave(ctx *gin.Context) {
	var (
		period string
		wave   model.UserComplaintWaveResponse
		err    error
	)
	period = strings.TrimSpace(strings.ToLower(ctx.DefaultQuery("period", "day")))
	if wave, err = bll.User.ComplainWave(ctx.Request.Context(), model.PERIOD(period)); err != nil {
		ctx.Error(err)
		return
	}
	utils.ResponseOK(ctx, wave)
}
func (a *app) activeUserBoard(ctx *gin.Context) {
	var (
		board model.ActiveUserBoardResponse
		err   error
	)
	if board, err = bll.User.ActiveUserBoard(ctx.Request.Context()); err != nil {
		ctx.Error(err)
		return
	}
	utils.ResponseOK(ctx, board)
}
func (a *app) activeUserWave(ctx *gin.Context) {
	var (
		period string
		wave   model.ActiveUserWaveResponse
		err    error
	)
	period = strings.TrimSpace(strings.ToLower(ctx.DefaultQuery("period", "day")))
	if wave, err = bll.User.ActiveUserWave(ctx.Request.Context(), model.PERIOD(period)); err != nil {
		ctx.Error(err)
		return
	}
	utils.ResponseOK(ctx, wave)
}

func (a *app) userSummary(ctx *gin.Context) {
	var (
		summary model.UserSummaryResponse
	)
	summary = bll.User.UserSummary(ctx.Request.Context())
	utils.ResponseOK(ctx, summary)
}
